﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Net;

namespace IMDBAPI
{
    [XmlType("root")]
    public class ImdbMovie
    {
        [XmlAttribute("title")]
        public string Name { get; set; }

        [XmlAttribute("year")]
        public string Year { get; set; }

        [XmlAttribute("rated")]
        public string Rated { get; set; }

        [XmlAttribute("released")]
        public string Released { get; set; }

        [XmlAttribute("runtime")]
        public string Runtime { get; set; }

        [XmlAttribute("genre")]
        public string GenreList { get; set; }

        [XmlAttribute("director")]
        public string Director { get; set; }

        [XmlAttribute("writer")]
        public string Writer { get; set; }

        [XmlAttribute("actors")]
        public string Actors { get; set; }

        [XmlAttribute("plot")]
        public string Plot { get; set; }

        //New
        [XmlAttribute("language")]
        public string Language { get; set; }

        //New
        [XmlAttribute("country")]
        public string Country { get; set; }

        //New
        [XmlAttribute("awards")]
        public string Awards { get; set; }

       
        [XmlAttribute("poster")]
        public string CoverURL { get; set; }

        //New
        [XmlAttribute("metascore")]
        public string Metascore { get; set; }

        [XmlAttribute("imdbRating")]
        public string Rating { get; set; }

        [XmlAttribute("imdbVotes")]
        public string Votes { get; set; }

        private string imdbid_text = "";
        [XmlAttribute("imdbID")]
        public string ImdbID { get { return imdbid_text; } set { imdbid_text = value; } }

        //New
        [XmlAttribute("type")]
        public string Type { get; set; }

        public byte[] CoverBinary
        {
            get
            {
                if (CoverURL != null && !CoverURL.Trim().Equals(""))
                {
                    WebClient webClient = new WebClient();
                    byte[] data = webClient.DownloadData(CoverURL);
                    return data;
                }
                return null;
            }
        }

        private static WebClient webClient = new WebClient();

        public void DownalodCoverAt(String localFile)
        {
            if (CoverURL != null && !CoverURL.Trim().Equals("") && !CoverURL.Trim().Equals("N/A"))
                {
                    Uri uri = new Uri(CoverURL);
                    webClient.DownloadFileAsync(uri,localFile);
                }
        }
    }
}
